package com.zeny.coding.controller.web;


import com.zeny.coding.constants.CourseConstants;
import com.zeny.coding.dto.CourseDto;
import com.zeny.coding.dto.Response;
import com.zeny.coding.dto.WebCourseDetailDto;
import com.zeny.coding.dto.WebCoursePageDto;
import com.zeny.coding.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h2>课程管理</h2>
 *
 * @Author Zeny
 */
@SuppressWarnings("all")
@RequestMapping("/coding/web/course")
@RestController
public class WebCourseController {

    @Autowired
    private CourseService courseService;

    /**
     * <h2>查询[num]门最新发布的课程</h2>
     * @param num
     **/
    @GetMapping("/list/{num}")
    public Response list(@PathVariable("num") Integer num) {
        List<CourseDto> courseDtoList = courseService.list(num);
        return new Response().success().data(courseDtoList).message(CourseConstants.QUERY_SUCCESS);
    }
    /**
     * <h2>条件查询,带条件</h2>
     * @param dto
     **/
    @PostMapping("/list")
    public Response list(@RequestBody WebCoursePageDto dto) {
        dto.check();
        this.courseService.pageQueryByCondition(dto);
        return new Response().success().data(dto);
    }

    /**
     * <h2>根据id查询课程【包括课程信息，大章，小节，教师】</h2>
     * @param id
     **/
    @GetMapping("/detail/{id}")
    public Response detail(@PathVariable("id") String id) {
        WebCourseDetailDto webCourseDetail = this.courseService.webCourseDetail(id);
        return new Response().success().data(webCourseDetail);
    }
}
